package org.ktjy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.ktjy.demoLian.entity.SysRole;
import org.ktjy.demoLian.entity.vo.SysRoleVo;
import org.ktjy.demoLian.page.PageUti;

import org.ktjy.demoLian.page.Role;
import org.ktjy.demoLian.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lwj
 * @since 2024-03-07
 */
@Controller
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private ISysRoleService sysRoleService;


    @RequestMapping("/list")
    public String list(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "") String roleName, Model model) {
        QueryWrapper<SysRole> queryWrapper=new QueryWrapper<>();
        List<SysRole> list;
        int count=0;
        int pageSize=2;
        if (roleName!=""&&roleName!=null){
            queryWrapper.lambda().like(SysRole::getRoleName,roleName);
            count= (int) sysRoleService.count(queryWrapper);
            list=sysRoleService.list(queryWrapper);
        }else {
            count= (int) sysRoleService.count();
            list=sysRoleService.list();
        }
        Role rolePage=new Role(count,pageSize,pageIndex);
        rolePage.setContent(list);
        model.addAttribute("rolePage",rolePage);
        return "role/list";
    }
}
